﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace HYFloorPipeModule
{
	public partial class FormFloorPipeMarking : System.Windows.Forms.Form
	{
		public double Length
		{
			get
			{
				return this._length;
			}
			set
			{
				this._length = value;
			}
		}

		public double Distance
		{
			get
			{
				return this._distance;
			}
			set
			{
				this._distance = value;
			}
		}

		public FormFloorPipeMarking(double distance, double length)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this._distance = distance;
			this._length = length;
			this.InitParaDataSetting(distance, length);
		}

		public void InitParaDataSetting(double distance, double length)
		{
			this.readDefaultValue();
			this.tbLength.Text = length.ToString(CultureInfo.InvariantCulture);
		}

		private void readDefaultValue()
		{
			this.setting = new UserSetting();
			this.tbDistance.Text = ((this.setting.GetValue("FloorPipeMark", "Distance") == "") ? "300" : this.setting.GetValue("FloorPipeMark", "Distance"));
		}

		private void writeDefaultValue()
		{
			this.setting = new UserSetting();
			this.setting.WriteValue("FloorPipeMark", "Distance", this.tbDistance.Text);
		}

		private void btnChoose_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Abort;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.tbLength.Text != "" && this.tbDistance.Text != "")
			{
				this._distance = double.Parse(this.tbDistance.Text);
				this._length = double.Parse(this.tbLength.Text);
				base.DialogResult = DialogResult.OK;
				this.writeDefaultValue();
				return;
			}
			YJKMessageBox.Information("参数不能为空");
			base.DialogResult = DialogResult.None;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void FormFloorPipeMarking_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (this.tbDistance.Text != "")
			{
				this.writeDefaultValue();
			}
		}

		private double _length;

		private double _distance;

		private UserSetting setting;
	}
}
